<?php
namespace control;
/*
*线索池类
*/

class cluePoolClass extends adIndexClass
{
    private const title = '线索池';
    private const page = 'cluePool';
    private const table = 'clue';

    /**
     * 字段初始化
     */
    public function fieldInit($fun): array
    {
        switch ($fun) {
            default:
                $tr = [
                    'name'          => [
                        'name'  => "{l.clue.homeForm.name}",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'companyName' => [
                        'name'  => "{l.clue.homeForm.companyName}",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'tel'  => [
                        'name'  => "{l.clue.homeForm.tel}",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'landline'         => [
                        'name'  => "{l.clue.homeForm.landline}",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'workFlow'          => [
                        'name'  => "{l.clue.homeForm.workFlow}",
                        'width' => 200,
                        'sort' => 1,
                    ],
                    'source'          => [
                        'name'  => "{l.clue.homeForm.source}",
                        'width' => 150,
                        'sort' => 1,
                    ],
                    'pool'          => [
                        'name'  => "{l.clue.homeForm.pool}",
                        'width' => 150,
                    ],
                    'time'          => [
                        'name'  => "{l.clue.homeForm.time}",
                        'width' => 150,
                        'sort' => 1,
                    ]
                ];
        }
        return $tr;
    }

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true)
    {
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    L('clue.homeForm.name') => text(array("name" => "name")),
                    L('clue.homeForm.companyName')   => text(array("name" => "companyName")),
                    L('clue.homeForm.tel') => text(array("name" => "tel")),
                ],
                [
                    L('clue.homeForm.landline')  => text(array("name" => "landline")),
                    L('clue.homeForm.workFlow') => select(array('name' => 'workFlow', 'option' => explode('，', para('clueWorkFlow')))),
                    L('clue.homeForm.pool') => selectMultiple(array('table' => 'pool', 'sqlField' => 'name','where'=>"type = '线索池' and coid = '".self::$coid."' order by list asc", 'sqlId' => 'id', 'name' => 'poolId', 'class' => 'width200')),
                ],
                [
                    L('clue.homeForm.source') => select(array('name' => 'source', 'option' => explode('，', para('clueSource')))),
                    L('clue.homeForm.time') => text(array("name" => "time", 'laydate' => ['type' => 'date', 'range' => '~']))
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /**
     * 查询表单
     * @return string
     */
    public function home(): string
    {
        $html = $this->homeOptions(false);
        //控件
        $button = "";
        $url = root . "control/adIndex.html?cla=" . self::page;
        if ($this->power(self::page, "edit")) {
            $button .= "<span onclick=\"layer('".self::page."','edit')\" class='spanButton'>".L('cluePool.home.new')."</span>\n
                        <span onclick=\"layer('" . self::page . "','transfer',{})\" class='spanButton'>".L('cluePool.home.allot')."</span>\n
                          <span onclick=\"layer('" . self::page . "','pool',{})\" class='spanButton'>".L('cluePool.home.cluePoolChange')."</span>\n";
        }
        //导入
        if ($this->power(self::page, 'import')) {
            $button .="<span class='spanButton' onclick=\"layer('importTemplate','importFrame',{cla:'".self::page."'})\">导入</span>";
        }
        if ($this->power(self::page, "export")) {
            $button .="<span class='spanButton' onclick=\"layer('importTemplate','exportFrame',{cla:'".self::page."'})\">导出</span>";
        }
        if ($this->power(self::page, "del")) {
            $button .= "<span class='spanButton' onclick=\"layer('{$this->get('cla')}', 'operate', {'act': 'del'})\">".L('cluePool.home.del')."</span>\n";
        }
        return $this->homeFun($this->search($html, layout: 'pop', toolButton: $button));
    }

    /**
     * 线索池负责人可以编辑，其余人只能查看和获取
     * 列表页-查询结果
     * @return bool|string
     */
    public function homeSearch(): bool|string
    {

        //全等查询数组
        $equal = array(
            'workFlow' => $this->post('workFlow'),
            'source' => $this->post('source'),
            'poolId' => $this->post('poolId'),
            'a.coid'=>self::$coid
        );
        $like = array(
            "a.name" => $this->post('name'),//姓名
            "companyName" => $this->post('companyName'),
            "tel" => $this->post('tel'),
            "landline" => $this->post('landline'),
            "text" => $this->post('text'),
        );
        $and = " and a.manager = ''";
        if (!$this->power(self::page, 'seeAll')) {
            $and .= " and if(b.isSee=1,(b.manager='" . self::$stid . "' or b.collaborator like '" . self::$stid . "'),b.manager='" . self::$stid . "')";
        }
        if ($this->post('time')) {
            $timeArr = explode(' ~ ', $this->post('time'));
            $and .= " and date(a.time) >='{$timeArr[0]}' and date(a.time) <='{$timeArr[1]}'";
        }
        //排序
        $orderBy = $this->listSort(array(
            "search"  => $this->post('list_sort_key') ?: 'time',
            "sort" => $this->post('list_sort') ?: "desc",
            "array"   => array(
                'time'=>'a.time'
            ),
        ));
        //获取查询结果
        $where = search(array("=" => $equal, 'like' => $like)) . $and;
        $page = $this->page(array(
            "table" => self::table." as a left join pool as b on a.poolId = b.id",
            "field"=>"a.*",
            "where" => $where,
            "order" => $orderBy['orderBy']
        ));
        $_SESSION[self::page]['sql'] = $page['fullSql'];
        //获取自定义字段参数
        $installSearch = $this->installSearch();
        $body          = [];
        //表格控件区
        $liButton = array(
            $this->checkAll("listForm", "listId")
        );
        //获取记录
        $url = root . "control/adIndex.html?cla=" . self::page;
        //获取记录
        foreach ($page['array'] as $array) {
            //列表控件
            $dominate = array(
                "box" => array("name" => "listId", "value" => $array['id']),
                "detail" => array("title" => L('cluePool.home.detail'), "click" => "newIframe('" . L('cluePool.home.detail') . "','" . $url . "&fun=detail&id=" . $array['id'] . "')"),
                "edit" => array("title" => L('cluePool.home.edit'), "click" => "layer('" . self::page . "','edit',{id:'" . $array['id'] . "'})"),
                'obtain' => array("title" => L('cluePool.home.obtain'), "click" => "layer('" . self::page . "','operate',{act:'obtain',id:'" . $array['id'] . "'})"),
            );
            $liButton[] = $this->dominate($dominate);
            //本行初始化
            $row = [];
            foreach ($installSearch['key'] as $key) {
                switch ($key) {
                    case "pool":
                        $pool = query('pool',"id = '$array[poolId]'");
                        $row[] = $pool['name'];
                        break;
                    default:
                        $row[] = isset($array[$key]) && $array[$key] ? $array[$key] : '';
                }
            }
            $body[] = $row;
        }
        //控件
        $button = "";
        //生成页面
        $li = $this->li(array(
            "body" => $body,
            "install" => $installSearch,
            "button" => array("html" => $liButton),
            "orderBySign" => $orderBy,
            "page" => $page['para'],
        ));
        //返回
        $json['html'] = $page['hint'] . $button . "<form name='listForm'>" . $li . "</form>" . $page['button'];
        return json_encode($json, 320);
    }

    /**
     * 分配
     */
    public function transfer()
    {
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . L('clue.transfer.manager')."：" => selectMultiple(array('table' => 'staff', "title" => L('clue.transfer.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'manager')),
            ),
            array(
                L('clue.transfer.collaborator')."：" => selectMultiple(array('table' => 'staff', 'multiple' => true, "title" => L('clue.transfer.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'collaborator[]')),
            ),

        )
        ));
        //返回
        return $this->layer(array("title" => L('cluePool.home.allot'), 'winFix' => true, "height" => 260, "html" => $html, 'formTwo' => 'listForm'));
    }

    /**
     * 分配编辑
     */
    public function transferEdit()
    {
        $listId = $this->post('id') ? [$this->post('id')] : $this->post('listId');
        $field = array(
            'lastFollowTime' => '',
            'manager' => $this->post('manager'),
            'collaborator' => $this->post('collaborator') && is_array($this->post('collaborator')) ? implode(',', array_unique($this->post('collaborator'))) : '',
        );
        if (!$this->power(self::page, 'edit')) {
            $json['warn'] = L('cluePool.transferEdit.power');
        } elseif (empty($listId) || !is_array($listId)) {
            $json['warn'] = L('cluePool.transferEdit.notFindClue');
        } elseif (empty($field['manager'])) {
            $json['warn'] = L('cluePool.transferEdit.choiceManage');
        } elseif (is_array($this->post('collaborator')) && in_array($field['manager'], $this->post('collaborator'))) {
            $json['warn'] = L('cluePool.transferEdit.choiceError');
        } else {
            $x = 0;
            //查看范围
            $field['see'] = implode(',', array_unique(array_filter(array_merge([$field['manager']], explode(',', $field['collaborator'])))));
            $manager = query('staff', "stid = '$field[manager]'");
            foreach ($listId as $id) {
                $info = query(self::table, " id = '$id'");
                $pool = query('pool', "id = '$info[poolId]'");
                if ($pool['manager'] == self::$stid || $this->power(self::page, 'seeAll')) {
                    if ($pool['isCooper']) {
                        //设置线索池负责人为协作人
                        $field['collaborator'] = array_unique(array_filter(array_merge(explode(',', $field['collaborator']), [$pool['manager']])));
                        $field['see'] = implode(',', array_unique(array_filter(array_merge([$field['manager']], $field['collaborator']))));
                        $field['collaborator'] = implode(',', $field['collaborator']);
                    }
                    $field['disTime'] = $this->time;
                    $warn = update(array(
                        'table' => self::table,
                        'field' => $field,
                        'where' => " id = '$id'"
                    ));
                    if ($warn == '更新成功') {
                        $x++;
                        $this->logWrite($id, '分配');
                        $text = str_replace(['{{staffName}}','{{name}}','{{id}}','{{manage}}'], [$this->control['name'],$info['name'],$id,$manager['name']], L('cluePool.transferEdit.logText'));
                        $this->logText(["type" => self::page, "text" => $text]);
                    }
                } else {
                    $text = str_replace(['{{staffName}}','{{name}}','{{id}}'], [$this->control['name'],$info['name'],$id], L('cluePool.transferEdit.failLog'));
                    $this->logText(["type" => self::page, "text" => $text]);
                }
            }
            $json['warn'] = 2;
            $_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('cluePool.transferEdit.warn'));
            $json['href'] = root.'control/adIndex.html?cla='.self::page.'&fun=home';
        }
        return json_encode($json, 320);
    }


    /**
     * 编辑页
     * @return string
     */
    public function edit()
    {
        $info = query(self::table, " id = '" . $this->post('id') . "' ");
        $tags = '';
        $kehu_label = find(array('table' => 'kehu_label', 'where'=>"targetId = '$info[id]' order by list asc"));
        foreach ($kehu_label['array'] as $array) {
            $tag_detail = query('tag_detail', "id = '$array[tag_detail_id]'");
            $tags .= "<span class='background-color-gray' style='margin-right: 5px'>{$tag_detail['name']}<input name='labelMxId[]' type='hidden' value='{$tag_detail['id']}'></span>";
        }
        //表单
        $html = $this->layerEdit([
            "table" => [
                [
                    must . L('clue.edit.name')."：" => text(["name" => "name", 'class' => 'text', "value" => $info['name']]),
                    L('clue.edit.companyName')."：" => text(["name" => "companyName", 'class' => 'text', "value" => $info['companyName']]),
                ],
                [
                    L('clue.edit.department')."：" => text(["name" => "department", 'class' => 'text', "value" => $info['department']]),
                    L('clue.edit.job')."：" => text(["name" => "job", 'class' => 'text', "value" => $info['job']]),
                ],
                [
                    L('clue.edit.tel')."：" => text(["name" => "tel", 'class' => 'text', "value" => $info['tel']]),
                    L('clue.edit.landline')."：" => text(["name" => "landline", 'class' => 'text', "value" => $info['landline']]),
                ],
                [
                    L('clue.edit.weChat')."：" => text(["name" => "weChat", 'class' => 'text', "value" => $info['weChat']]),
                    L('clue.edit.qq')."：" => text(["name" => "qq", 'class' => 'text', "value" => $info['qq']]),
                ],
                [
                    L('clue.edit.website')."：" => text(["name" => "website", 'class' => 'text', "value" => $info['website']]),
                    L('clue.edit.email')."：" => text(["name" => "email", 'class' => 'text', "value" => $info['email']]),
                ],
                [
                    L('clue.edit.address')."：" => text(["name" => "address", 'title' => L('clue.edit.keyword'), 'class' => 'text', "value" => $info['address']]) . (componentClass::addressIco("layer('client','map',{})")) .
                        hidden(array('name' => 'location', 'value' => $info['lng'] ? ($info['lat'] . ',' . $info['lng']) : '')).
                        hidden(array('name' => 'region', 'value' => $info['region']?:'')),
                    L('clue.edit.source')."：" => select(["name" => "source", 'class' => 'text', 'title' => L('clue.edit.choice'), 'option' => explode('，', para('clueSource')), "value" => $info['source']]),
                ],
                [
                    L('clue.edit.tags')."：" =>"<span id='tags'>{$tags}</span><span class='spanButton' style='margin:0' onclick=\"layer('client','add_label',$('form[name=cluePoolEditForm]').serialize())\">".L('clue.edit.addTags')."</span>",
                ],
                [
                    L('clue.edit.workFlow')."：" => select(["name" => "workFlow", 'class' => 'text', 'title' => L('clue.edit.choice'), 'option' => explode('，', para('clueWorkFlow')), "value" => $info['workFlow']]),
                    L('clue.edit.followTime')."：" => text(["name" => "followTime", 'laydate' => ['type' => 'datetime'], 'class' => 'text', "value" => $info['followTime']]),
                ],
                [
                    L('clue.edit.manager')."：" => selectMultiple(array('table' => 'staff', "title" => L('clue.edit.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'manager', 'value' => $info['manager'])),
                    L('clue.edit.collaborator')."：" => selectMultiple(array('table' => 'staff', 'where' => " stid !='$info[manager]'", 'multiple' => true, "title" => L('clue.edit.choice'), 'sqlField' => 'name', 'sqlId' => 'stid', 'name' => 'collaborator[]', 'value' => $info['collaborator'])),
                ],
                [
                    L('clue.edit.pool')."：" => selectMultiple(array('name' => 'poolId', 'title' => L('clue.edit.choice'), 'table' => 'pool', 'where' => "type = '线索池' and coid = '".self::$coid."'", 'sqlId' => 'id', 'sqlField' => 'name', 'value' => $info['poolId'])),
                ],
                [
                    L('clue.edit.remark')."：" => textarea(["name" => "text", 'class' => 'textarea', "value" => $info['text']])
                ],
            ],
        ]);
        $html .= <<<efo
<script>
$(function(){
    $("input[name='address']").bigAutocomplete({
        // width:543,
        url:root + 'control/adIndex.html?cla=component&fun=getAddress',
        callback:function(data){
            $("[name='location']").val(data.location)
        }
    });

})
</script>
efo;
        //返回
        return $this->layer(array("title" => L('job.button.editor').self::title, "height" => 600, "html" => $html));
    }

    public function editEdit()
    {
        $id = $this->post('id') ?: self::getId();
        $labelMxId = $this->post('labelMxId');//标签ID
        $field = [
            'name' => $this->post('name'),
            'companyName' => $this->post('companyName'),
            'department' => $this->post('department'),
            'job' => $this->post('job'),
            'tel' => $this->post('tel'),
            'landline' => $this->post('landline'),
            'region'       => $this->post('region'),
            'weChat' => $this->post('weChat'),
            'qq' => $this->post('qq'),
            'website' => $this->post('website'),
            'email' => $this->post('email'),
            'address' => $this->post('address'),
            'source' => $this->post('source'),
            'workFlow' => $this->post('workFlow'),
            'followTime' => $this->post('followTime'),
            'poolId' => $this->post('poolId') ?: clueClass::defaulPoolId(),
            'manager' => $this->post('manager'),
            'collaborator' => $this->post('collaborator') && is_array($this->post('collaborator')) ? implode(',', array_unique($this->post('collaborator'))) : '',
            'text' => $this->post('text'),
            'updateTime' => $this->time
        ];
        $annotation = [
            'name' => L('cluePool.editEdit.name'),
//            'tel' => '手机',
//            'email' => '邮箱',
//            'qq' => 'QQ号码',
//            'website' => '网址',
        ];
        $rules = [
            'name' => 'required',
//            'tel' => 'tel',
//            'email' => 'email',
//            'qq' => 'numeric',
//            'website' => 'url',
        ];
        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        //判断
        if (!$this->power(self::page, "edit")) {
            $json['warn'] = L('cluePool.editEdit.power');
        } elseif (empty($field['tel']) && empty($field['landline'])) {
            $json['warn'] = L('cluePool.editEdit.telLandline');
        } elseif (!empty($field['tel']) && preg_match(checkTel, $field['tel']) == 0) {
            $json['warn'] = L('cluePool.editEdit.telError');
        } elseif (!empty($field['email']) && preg_match(checkEmail, $field['email']) == 0) {
            $json['warn'] = L('cluePool.editEdit.emailError');
        } elseif (!empty($field['qq']) && preg_match(checkInteger, $field['qq']) == 0) {
            $json['warn'] = L('cluePool.editEdit.qqError');
        } elseif (!empty($field['website']) && preg_match(checkUrl, $field['website']) == 0) {
            $json['warn'] = L('cluePool.editEdit.websiteError');
        } elseif (is_array($this->post('collaborator')) && in_array($field['manager'], $this->post('collaborator'))) {
            $json['warn'] = L('cluePool.editEdit.collaboratorError');
        } elseif (!empty($field['companyName']) && static::total(array('table'=>self::table,'where'=>"companyName = '$field[companyName]' and id !='$id'"))>0) {
            $json['warn'] = L('cluePool.editEdit.companyNameRepeat');
        }  else {
            //查看范围
            $field['see'] = implode(',', array_unique(array_merge(explode(',', $field['collaborator']), [$field['manager']])));
            // 经纬度及地区处理
            if ($this->post('location')){
                $location = explode(',', $this->post('location'));
                $field['lat'] = $location[0];
                $field['lng'] = $location[1];
                if(empty($field['region'])) {
                    $region = componentClass::coordinateToAddr($field['lat'], $field['lng']);
                    if ($region['err_code'] == 0) {
                        $field['region'] = $region['data']['address_component']['province'] . '-' . $region['data']['address_component']['city'] . '-' . $region['data']['address_component']['district'];
                    }
                }
            }

            $where = " id = '$id' ";
            $info = query(self::table, $where);
            if (!$info['id']) {
                $field = array_merge($field, [
                    'id' => $id,
                    'coid'=>self::$coid,
                    'stid' => $this->control['stid'],
                    'time' => $this->time
                ]);
                $json['warn'] = static::insert(["table" => self::table, "field" => $field]);
            } else {
                $json['warn'] = static::update([
                    "table" => self::table,
                    "field" => $field,
                    "where" => $where
                ]);
            }
            if (in_array($json['warn'], ["新增成功", "更新成功"])) {
                $tagsText = '';
                //添加标签
                $kehu_label_id = [];
                if (!empty($labelMxId) && is_array($labelMxId)) {
                    foreach ($labelMxId as $tagsId) {
                        $kehu_label = query('kehu_label', "targetId = '$id' and tag_detail_id = '$tagsId'");
                        $tags_detail = query('tag_detail', "id = '$tagsId'");
                        $tags = query('tag', "id = '$tags_detail[orderId]'");
                        $tagsText .= $tags_detail['name'] . ',';
                        if (empty($kehu_label['id'])) {
                            $mid = self::getId();
                            $kehu_label_id[] = $mid;
                            static::insert(array(
                                'table' => 'kehu_label',
                                'field' => [
                                    'id' => $mid,
                                    'coid'=>self::$coid,
                                    'targetId' => $id,
                                    'tag_detail_id' => $tagsId,
                                    'tagId' => $tags['id'],
                                    'type' => 0,
                                    'time' => $this->time,
                                ]
                            ));
                        } else {
                            $kehu_label_id[] = $kehu_label['id'];
                        }
                    }
                }
                //删除无效关联的标签
                delete(array('table' => 'kehu_label', 'where' => "id not in ('" . implode("','", $kehu_label_id) . "') and targetId = '$id'"));
                update(array('table' => self::table, 'field' => ['tags' => $tagsText], 'where' => "id = '$id'"));

                //添加日志
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = str_replace(['{{staffName}}','{{type}}','{{id}}'], [$this->control['name'],$type,$id], L('cluePool.editEdit.log'));
                $this->logWrite($id, $type);
                $this->logText(["type" => self::page, "text" => $text]);
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
                $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=detail&id=" . $id;
            }
        }

        resp:
        return json_encode($json, 320);
    }

    /*详情页*/
    public function detail(): string
    {
        $info = query(self::table, " id = '".$this->get('id')."'");
        if (empty($info['id'])) {
            $html = L('cluePool.detail.empty');
        } else {
            //菜单
            $data = array(
                "id" => $info['id'],
                "title" => L('cluePool.detail.detail'),
            );
            $pool = query('pool', "id = '$info[poolId]'");
            $button = [];
            if ($this->power(self::page, "edit")) {
                //按钮
                $button[] = [
                    "name" => L('cluePool.detail.edit'),
                    "type" => "弹出层",
                    "cla" => $this->get('cla'),
                    "fun" => "edit",
                    "post" => ["id" => $info['id']],
                    'style' => 'li-btn-blue-bg',
                ];

                //按钮
                $button[] = [
                    "name" => L('cluePool.detail.allot'),
                    "type" => "点击事件",
                    "title" => L('cluePool.detail.allot'),
                    'fun' => "layer('" . self::page . "','transfer',{id:'" . $info['id'] . "'})",
                ];
                //按钮
                $button[] = [
                    "name" => L('cluePool.detail.cluePoolChange'),
                    "type" => "点击事件",
                    "title" => L('cluePool.detail.cluePoolChange'),
                    'fun' => "layer('" . self::page . "','pool',{id:'" . $info['id'] . "'})",
                ];

            }
            //按钮
            $button[] = [
                "name" => L('cluePool.detail.obtain'),
                "type" => "弹出层",
                "cla" => $this->get('cla'),
                "fun" => "operate",
                "post" => ["act" => 'obtain', "id" => $info['id']],
            ];
            if ($this->power(self::page, "del")) {
                //按钮
                $button[] = [
                    "name" => L('cluePool.detail.del'),
                    "type" => "弹出层",
                    "cla" => $this->get('cla'),
                    "fun" => "operate",
                    "post" => ["act" => 'del', "id" => $info['id']],
                ];
            }
            /******标签*********/
            $tags = '';
            $kehu_label = find(array('table' => 'kehu_label', 'where'=>"targetId = '$info[id]' order by list asc"));
            foreach ($kehu_label['array'] as $array) {
                $tag_detail = query('tag_detail', "id = '$array[tag_detail_id]'");
                $tags .= "<span class='background-color-gray' style='margin-right: 5px'>{$tag_detail['name']}</span>";
            }
            //生成表单
            $data['button'] = $this->tableShowButton($button);
            $data['html'] = $this->tableShow(array(
                "详细信息" => array(
                    array(
                        L('cluePool.detail.name') => $info['name'],
                        L('cluePool.detail.companyName') => $info['companyName'],
                        L('cluePool.detail.department') => $info['department'],
                        L('cluePool.detail.job') => $info['job'],
                    ),
                    array(
                        L('cluePool.detail.birthDay') => text(array('name' => 'birthDay', 'title' =>L('cluePool.detail.birthDayWrite'), 'class' => 'display-hidden', 'laydate' => ['done' => "function(value, date, endDate){setVal(value)}"], 'value' => self::null($info['birthDay'], false))),
                    ),
                ),
                L('cluePool.detail.contactInfo') => array(
                    array(
                        L('cluePool.detail.tel') => $info['tel'],
                        L('cluePool.detail.landline') => $info['landline'],
                        L('cluePool.detail.weChat') => $info['weChat'],
                        L('cluePool.detail.qq') => $info['qq'],
                    ),
                    array(
                        L('cluePool.detail.website') => $info['website'],
                        L('cluePool.detail.email') => $info['email'],
                    ),
                ),
                L('cluePool.detail.manageInfo') => array(
                    array(
                        L('cluePool.detail.source') => $info['source'],
                        L('cluePool.detail.tags') => $tags,
                        L('cluePool.detail.workFlow') => $info['workFlow'],
                        L('cluePool.detail.followTime') => $info['followTime'],
                    ),
                    array(
                        L('cluePool.detail.belongPool') => self::setBackGroundColorGray($pool['name']),

                    ),
                ),
                L('cluePool.detail.sys') => array(
                    array(
                        L('cluePool.detail.stid') => self::findStaff($info['stid']) . hidden(array('name' => 'id', 'value' => $info['id'])),
                        L('cluePool.detail.time') => $info['time'],
                        L('cluePool.detail.updateTime') => $info['updateTime'],
                    ),
                )
            ));
            //生成页面
            $data['html'] .= <<<efo
<style>
.display-hidden{border: none}
.display-hidden:focus{border: 1px solid #d7d7d7;line-height: 16px;
    height: 16px;
    width: 200px;
    padding: 6px;
    border-radius: 4px;}
</style>
<script>
function setVal(value){
      let id = $("[name='id']").val();
     $.post(root+'control/adIndex.html?cla={$this->get('cla')}&fun=setVal',{id:id,value:value},function(res) {
                if(res.warn !== 1){
                   warn(res.warn)
                }
            },'json')
}
</script>
efo;

            $html = $this->tab($data);
        }
        //返回
        return $html;
    }

    /**
     * 填写生日
     * @return bool|string
     */
    public function setVal()
    {
        $id = $this->post('id');
        $value = $this->post('value');
        $info = query(self::table, " id = '$id' ");
        if (!$this->power(self::page, 'edit')) {
            $json['warn'] = L('cluePool.setVal.power');
        } elseif (empty($info['id'])) {
            $json['warn'] = L('cluePool.setVal.empty');
        } elseif (!in_array(self::$stid, explode(',', $info['see']))) {
            $json['warn'] = L('cluePool.setVal.notManage');
        } else {
            $json['warn'] = update([
                'table' => self::table,
                'field' => [
                    'birthDay' => $value,
                ],
                'where' => " id = '$id' "
            ]);
            if ($json['warn'] == '更新成功') {
                $json['warn'] = 1;
                $this->logWrite($id, '更新');
            }
        }
        return json_encode($json, 320);
    }

    /**
     * 获取
     */
    public function obtain(): bool|string
    {
        $id = $this->post('id');
        //线索
        $info = query(self::table, " id = '$id'");
        //先判断他是不是此线索池的能查看到的人
        if (empty($info['id'])) {
            $json['warn'] = L('cluePool.obtain.empty');
        } elseif (!empty($info['manager'])) {
            $json['warn'] = L('cluePool.obtain.obtainOther');
        } else {
            $pool = query('pool', "id = '$info[poolId]'");
            $field = [
                'manager' => self::$stid,
                'see' => self::$stid,
                'collaborator' => '',
                'lastFollowTime' => '',
                'disTime' => $this->time,
                'updateTime' => $this->time,
            ];
            if ($pool['isCooper']) {
                //设置线索池负责人为协作人
                $field['collaborator'] = array_unique(array_filter(array_merge(explode(',', $field['collaborator']), [$pool['manager']])));
                $field['see'] = implode(',', array_unique(array_filter(array_merge([$field['manager']], $field['collaborator']))));
                $field['collaborator'] = implode(',', $field['collaborator']);
            }
            $warn = update(array(
                'table' => self::table,
                'field' => $field,
                'where' => " id = '$info[id]'"
            ));
            if ($warn == '更新成功') {
                $text = str_replace(['{{staffName}}','{{name}}','{{id}}'], [$this->control['name'],$info['name'],$id], L('cluePool.obtain.logText'));
                $this->logText(["type" => self::page, "text" => $text]);
                //日志
                $this->logWrite($id, '获取', str_replace(['{{staffName}}'], [$this->control['name']], L('cluePool.obtain.logWrite')));
            }
            $json['warn'] = 2;
            $_SESSION['warn'] = L('cluePool.obtain.success');
        }
        return json_encode($json, 320);
    }

    /**
     * 展示姓名
     * @param $member
     * @param int $style
     * @return string
     */
    public static function showMember($member, $style = 1): string
    {
        $result = '';
        if ($member) {
            $memberArr = !is_array($member) ? explode(',', $member) : $member;
            foreach ($memberArr as $stid) {
                $name = self::findStaff($stid);
                if ($style == 1) {
                    $result .= self::setBackGroundColorGray($name);
                } else {
                    $result .= ',' . $name;
                }
            }
        }
        if ($style !== 1 && $result) {
            $result = ltrim($result, ',');
        }
        return $result;
    }

    /**
     * 添加背景颜色
     * @param $text
     * @return string
     */
    public static function setBackGroundColorGray($text): string
    {
        return "<span class='background-color-gray'>{$text}</span>";
    }



    /**
     * 下载模板
     */
    public function downloadModel()
    {
        $templateId = $this->get('templateId');
        if (!$this->power(self::page, 'import')) {
            $_SESSION['warn'] = L('cluePool.downloadModel.power');
        } else {
            $exampleData[] = ['邱女士','重庆雨木科技','总经办','行政','13000000000','44340001','1995-01-01','wechat001','10001','www.yumukeji.com','001@yumukeji.com',
                '重庆市南岸区国际社区','官网','初次联系','2021-01-01 00:00:00','默认线索池(不填也为默认线索池)','张三','YM202111220001','李四,王五','YM202111220002,YM202111220003',
                '(样例数据，导入时请删除本条数据)'];

            $excel    = $this->excelHead();
            $fileName = self::title.'导入模板-'.importTemplateClass::getName($templateId).'.xlsx';
            $filePath = $excel->fileName($fileName, 'sheet1');
            $format = new \Vtiful\Kernel\Format($filePath->getHandle());
            $templateField = importTemplateClass::templateField(self::page, 'importFieldInit', id:$templateId);
            $index         = 0;
            foreach ($templateField as $k => $array) {
                if ($array['display']){
                    $backgroundStyle=null;
                    if (importTemplateClass::getIsMustValue($this->importFieldInit(), $array['columnName'])){
                        //必填项判断
                        $backgroundStyle  = $format->background(
                            0xFFC04B
                        )->toResource();
                    }
                    $filePath->insertText(0, $index, $array['aliasName'],'',$backgroundStyle);
                    foreach ($exampleData as $y=>$example){
                        $exampleVal = match ($array['columnName']){
                            '姓名'=>$example[0],
                            '公司名称'=>$example[1],
                            '部门'=>$example[2],
                            '职务'=>$example[3],
                            '手机'=>$example[4],
                            '电话'=>$example[5],
                            '出生年月'=>$example[6],
                            '微信号'=>$example[7],
                            'QQ号'=>$example[8],
                            '网址'=>$example[9],
                            '邮箱'=>$example[10],
                            '地址'=>$example[11],
                            '线索来源'=>$example[12],
                            '跟进状态'=>$example[13],
                            '下次跟进时间'=>$example[14],
                            '所属线索池'=>$example[15],
                            '负责人'=>$example[16],
                            '负责人编号'=>$example[17],
                            '协作人'=>$example[18],
                            '协作人编号'=>$example[19],
                            '备注'=>$example[20],
                            default=>'',
                        };
                        $filePath->insertText($y+1, $index, $exampleVal);
                    }
                    $index++;
                }
            }
            $text = str_replace(['{{staffName}}'], [$this->control['name']], L('cluePool.downloadModel.log'));
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOutPut($filePath,$fileName);
            exit(0);
        }
        header("Location:" . getenv("HTTP_REFERER"));
    }



    /*数据导入*/
    public function importData()
    {
        $templateId = $this->post('templateId');
        if (!$this->power(self::page, 'import')) {
            $json['warn'] = L('cluePool.importData.power');
        } else {
             $fomatArray = [];//导入数据格式同一为TYPE_STRING
            foreach ($this->importFieldInit() as $value){
                $fomatArray[] = \Vtiful\Kernel\Excel::TYPE_STRING;
            }
            $data = $this->importHead(format: $fomatArray);
            $x = 0;
            $text = '';
            $headArray = [];
            $row_list=0;
            foreach ($data as $i => $row) {
                $row_list++;
                if ($i==0){
                    $templateField = importTemplateClass::templateField(self::page, 'importFieldInit', id:$templateId);
                    $headArray = importTemplateClass::combinHead($templateField,$row);
                }
                if ($i > 0) {
                    $rowData = formSubArray($row);
                    //只接收模板中选中的字段的值
                    $cell = [];
                    foreach ($headArray as $index=>$headName){
                        $cell[$headName] = $rowData[$index]??'';
                    }
                    //初始化未被模板需要的字段的值
                    foreach ($this->importFieldInit() as $value){
                        $cell[$value['columnName']] = $cell[$value['columnName']]??'';
                    }
                    $manager = query("staff", "orderNo = '$cell[负责人编号]'");
                    $partner = explode(',', $cell['协作人编号']);

                    $collaborator = [];
                    foreach ($partner as $stid) {
                        $staff = query('staff', "orderNo = '$stid'");
                        if ($cell['协作人编号'] && $staff['stid']){
                            $collaborator[] = $staff['stid'];
                        }
                    }

                    $pool = query('pool', "name = '$cell[所属线索池]' and type = '线索池' and coid = '".self::$coid."'");

                    // $title = ['姓名', '公司姓名', '部门', '职务','手机','电话','微信号','QQ号','网址','邮箱','地址','线索来源','跟进状态','下次跟进时间','所属线索池','负责人','负责人编号','协作人','协作人编号(多个用英文逗号隔开)','备注'];
                    $field = [
                        'id'=>self::getId(),
                        'coid'=>self::$coid,
                        'name' => $cell['姓名'],
                        'companyName'  => $cell['公司姓名'] ?: $cell['姓名'],
                        'department'   => $cell['部门'],
                        'job'          => $cell['职务'],
                        'tel'          => $cell['手机'],
                        'landline'     => $cell['电话'],
                        'birthDay'     => $cell['出生年月'],
                        'weChat'       => $cell['微信号'],
                        'qq'           => $cell['QQ号'],
                        'region'=>'',
                        'lat'=>'',
                        'lng'=>'',
                        'website'      => $cell['网址'],
                        'email'        => $cell['邮箱'],
                        'address'      => $cell['地址'],
                        'source'       => $cell['线索来源'],
                        'workFlow'     => $cell['跟进状态'],
                        'followTime'   => $cell['下次跟进时间'],
                        'poolId' => $pool['id'] ?: clueClass::defaulPoolId(),
                        'manager' => $cell['负责人编号']?$manager['stid']:'',
                        'collaborator' => implode(',', array_filter(array_unique($collaborator))),
                        'text'         => $cell['备注'],
                        'updateTime' => $this->time
                    ];
                    $annotation = [
                        'name' => L('cluePool.importData.name'),
                    ];
                    $rules = [
                        'name' => 'required',
                    ];
                    // 校验是否符合规则
                    $vt = new \verify();
                    $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
                    if (!empty($cell[16]) && !$manager['stid']) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.empty'));
                    } elseif ($result === false) {
                        $text .= "\n".str_replace(['{{i}}'], [$row_list], L('cluePool.importData.validateError')) . $vt->getErrs()[0];
                    } elseif (!empty($field['tel']) && preg_match(checkTel, $field['tel']) == 0) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.telError'));
                    } elseif (!empty($field['email']) && preg_match(checkEmail, $field['email']) == 0) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.emailError'));
                    } elseif (!empty($field['qq']) && preg_match(checkInteger, $field['qq']) == 0) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.qqError'));
                    } elseif (!empty($field['website']) && preg_match(checkUrl, $field['website']) == 0) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.websiteError'));
                    } elseif (!empty($field['tel']) && static::total(array('table'=>self::table,'where'=>"tel = '$field[tel]'"))>0) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.telRepeat'));
                    } elseif (!empty($field['landline']) && static::total(array('table'=>self::table,'where'=>" landline = '$field[landline]'"))>0) {
                        $text .= str_replace(['{{i}}'], [$row_list], L('cluePool.importData.landlineRepeat'));
                    }else {
                        //查看范围
                        $field['see'] = implode(',',array_filter(array_unique(array_merge(explode(',', $field['collaborator']), [$field['manager']]))));
                        if (!empty($field['address'])){
                            //解析地址信息 得到经纬度和省市区
                            $locationRes= componentClass::addrToCoordinate($field['address']);
                            if ($locationRes['err_code'] == 0) {
                                $field['lat'] = $locationRes['data']['location']['lat'];
                                $field['lng'] = $locationRes['data']['location']['lng'];
                                $region = componentClass::coordinateToAddr($field['lat'], $field['lng']);
                                if ($region['err_code'] == 0) {
                                    $field['region'] = $region['data']['address_component']['province'] . '-' . $region['data']['address_component']['city'] . '-' . $region['data']['address_component']['district'];
                                }
                            }
                        }
                        $warn = insert(["table" => self::table, "field" => $field]);
                        if (in_array($warn, ["新增成功", "更新成功"])) {
                            $x++;
                            $text .=  "第{$row_list}行导入成功<br>";
                        } else {
                            $text .= "第{$row_list}行导入失败：{$warn}<br>";
                        }
                    }
                }
            }
            $total = count($data)-1;
            $json['data'] = [
                'text'=>$text,
                'title'=>"您导入了{$total}条数据，成功{$x}条，失败".($total-$x)."条",
            ];
            $text = str_replace(['{{staffName}}','{{fileName}}'], [$this->control['name'],$_FILES['file']['name']], L('cluePool.importData.log')) . $text;
            $this->logText(["type" => self::page, "text" => $text]);
            $json['warn'] = 2;
        }
        return json_encode($json,320);
    }

    /**
     * 导出
     */
    public function exportData()
    {
        $templateId = $this->get('templateId');
        $checkedId = $this->get('checkedId')?explode(',',$this->get('checkedId')):[];
        if (!$this->power(self::page, 'export')) {
            $_SESSION['warn'] = L('cluePool.exportData.power');
        }  else {
            $data = [];
            /***********标题**********/
            $title =[];
            $tempFieldAll = importTemplateClass::templateField(self::page, 'exportFieldInit', id:$templateId);
            foreach ($tempFieldAll as $array) {
                if ($array['display']){
                    $title[] = $array['aliasName'];
                }
            }
            //判断是否选中导出
            if (!self::is_null_array($checkedId)){
                $result = find(array(
                    "table" => self::table." as a left join pool as b on a.poolId = b.id",
                    "field"=>"a.*",
                    "where" => "a.id in ('".implode("','", $checkedId)."') order by a.time desc",
                ))['array'];
            }else{
                $sql   = $_SESSION[self::page]['sql'];
                $result   = sqlFind($sql);
            }
            //导出数据生成
            foreach ($result as $array){
                $column = [];
                $pool = query('pool', " id = '$array[poolId]'");
                $tags = '';
                $kehu_label = find(array('table' => 'kehu_label', 'where'=>"targetId = '$array[id]' order by list asc"));
                foreach ($kehu_label['array'] as $val) {
                    $tag_detail = query('tag_detail', "id = '$val[tag_detail_id]'");
                    $tags .= $tag_detail['name'].',';
                }
                foreach ($tempFieldAll as $templateField){
                    if ($templateField['display']){
                        $column[] = match ($templateField['columnName']){
                            '姓名'=>$array['name'],
                            '公司名称'=>$array['companyName'],
                            '部门'=>$array['department'],
                            '职务'=>$array['job'],
                            '出生年月'=>$array['birthDay'],
                            '手机'=>$array['tel'],
                            '电话'=>$array['landline'],
                            '微信号'=>$array['weChat'],
                            'QQ号'=>$array['qq'],
                            '网址'=>$array['website'],
                            '邮箱'=>$array['email'],
                            '地址'=>$array['address'],
                            '线索来源'=>$array['source'],
                            '跟进状态'=>$array['workFlow'],
                            '下次跟进时间'=>$array['followTime'],
                            '所属线索池'=>$pool['name'],
                            '标签'=>$tags,
                            '负责人'=>self::findStaff($array['manager']),
                            '协作人'=>self::showMember($array['collaborator'], 2),
                            '备注'=>$array['text'],
                            '创建人'=>self::findStaff($array['stid']),
                            '更新时间'=>$array['updateTime'],
                            '创建时间'=>$array['time'],
                            default=>'',
                        };
                    }
                }
                $data[] = $column;
            }
            $text = str_replace(['{{staffName}}'], [$this->control['name']], L('cluePool.exportData.log'));
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOut($title, $data, L('cluePool.exportData.fileName').".xlsx");
            exit(0);
        }
        header("Location:" . getenv("HTTP_REFERER"));

    }


    // 操作中转
    public function operate()
    {
        $act = $this->post('act') ?? '';
        $pwd = false; // 需要密码
        $form = $word = $power = '';
        switch ($act) {
            case 'obtain':
                //获取
                $act = 'see';
                $msg = L('cluePool.operate.obtain');
                $title = L('cluePool.operate.obtainTitle');
                $function = 'obtain';
                $form = self::page . 'OperateForm, listForm';
                $word = true;

                break;
            default:
                $act = 'del';
                $msg = L('cluePool.operate.del');
                $title = self::page . 'Delete';
                $function = 'delete';
                $form = self::page . 'OperateForm, listForm';
                $power = '';
                break;
        }
        if (!$this->power(self::page, $act)) {
            $_SESSION['warn'] = str_replace(['{{msg}}'], [$msg], L('cluePool.exportData.warn'));
            $json = [
                'warn' => 2,
                'href' => root . 'control/adIndex.html?cla=' . $this->get('cla') . '&fun=home',
            ];
        } else {
            return $this->confirm([
                'title' => $title,
                'function' => $function,
                'form' => $form,
                'power' => $power,
                'pwd' => $pwd,
                'word' => $word,
            ]);
        }

        resp:
        return json_encode($json, 320);
    }


    /**
     * 删除
     * @return bool|string
     */
    public function delete()
    {
        $array = $this->post('listId') ?? $this->post('id');
        if (!$this->power(self::page, "del")) {
            $json['warn'] = L('cluePool.delete.power');
        } elseif (empty($array)) {
            $json['warn'] = L('cluePool.delete.noChoice');
        } else {
            $text = "";
            $x = 0;
            $array = is_array($array) ? $array : [$array];
            foreach ($array as $id) {
                $info = query(self::table, " id = '$id' ");
                $result = find(array('table' => 'file', 'where' => "targetId = '$id'"));
                foreach ($result['array'] as $file) {
                    fileDelete($file['src']);
                }
                //删除附件
                delete(array("table" => "file", "where" => " targetId = '$id' "));
                //删除标签
                delete(array("table" => "kehu_label", "where" => " targetId = '$id' "));
                //删除跟进记录
                delete(array("table" => "follow", "where" => " targetId = '$id' "));
                //删除操作日志
                delete(array("table" => "clue_log", "where" => " orderId = '$id' "));
                //最后删除基本参数
                delete(array("table" => self::table, "where" => " id = '$id' "));
                //返回
                $warn = L('cluePool.delete.success');
                $x++;
                $text .= str_replace(['{{id}}'], [$info['id']], L('cluePool.delete.text')) . $warn . "。<br>";
            }
            //添加日志
            $text = str_replace(['{{staffName}}'], [$this->control['name']], L('cluePool.delete.log')) . "<br>" . $text;
            $this->logText(array("type" => self::page, "text" => $text));
            $_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('cluePool.delete.warn'));
            $json['warn'] = 2;
            $json['href'] = root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=home";
        }
        return json_encode($json, 320);
    }


    /**
     * 日志写入
     */
    public function logWrite($id, $type, $text = '')
    {
        $info = query(self::table, " id = '$id'");
        insert(array(
            'table' => 'clue_log',
            'field' => [
                'id' => self::getId(),
                'coid'=>self::$coid,
                'orderId' => $id,
                'classify' => '线索',
                'type' => $type,
                'text' => $text ?: $this->control['name'] . $type . '了线索【' . $info['name'] . '】',
                'staffName' => $this->control['name'],
                'stid' => $this->control['stid'],
                'time' => $this->time
            ]
        ));

    }

    /**
     * 转到线索池
     */
    public function pool()
    {
        //生成表单
        $html = $this->layerEdit(array("table" => array(
            array(
                must . L('cluePool.pool.cluePool')."：" => selectMultiple(array('table' => 'pool', 'where' => "type = '线索池' and coid = '".self::$coid."'", "title" => L('cluePool.pool.choice'), 'sqlField' => 'name', 'sqlId' => 'id', 'name' => 'poolId')),
            ),
        )
        ));
        //返回
        return $this->layer(array("title" => L('cluePool.pool.transferToCluePool'), 'winFix' => true, "height" => 200, "html" => $html, 'formTwo' => 'listForm'));
    }

    /**
     *  转到线索池编辑
     */
    public function poolEdit()
    {
        $listId = $this->post('id') ? [$this->post('id')] : $this->post('listId');
        $poolId = $this->post('poolId');
        $pool = query('pool', "id = '$poolId'");
        if (!$this->power(self::page, 'edit')) {
            $json['warn'] = L('cluePool.poolEdit.power');
        } elseif (empty($listId) || !is_array($listId)) {
            $json['warn'] = L('cluePool.poolEdit.emptyClue');
        } elseif (empty($pool['id'])) {
            $json['warn'] = L('cluePool.poolEdit.empty');
        } else {
            $x = 0;
            foreach ($listId as $id) {
                //线索
                $info = query(self::table, " id = '$id'");
                $warn = update(array(
                    'table' => self::table,
                    'field' => [
                        'poolId' => $pool['id'],
                    ],
                    'where' => "id = '$id'"
                ));
                if (in_array($warn, ['新增成功', '更新成功'])) {
                    $x++;
                    $text = str_replace(['{{staffName}}','{{name}}','{{id}}','{{pool}}'], [$this->control['name'],$info['name'],$id,$pool['name']], L('cluePool.poolEdit.logText'));
                    $this->logText(["type" => self::page, "text" => $text]);
                    //日志
                    $this->logWrite($id, '变更线索池', str_replace(['{{staffName}}'], [$this->control['name']], L('cluePool.poolEdit.logWrite')));
                }
            }
            $json['warn'] = 2;
            $_SESSION['warn'] = str_replace(['{{x}}'], [$x], L('cluePool.poolEdit.warn'));
        }
        return json_encode($json, 320);
    }

    /**
     * 导入模板字段初始化
     * @return array[]
     */
    public function importFieldInit($classify=''): array
    {
        return match ($classify) {
            default=>  [
                [
                    'columnName'=>'姓名',
                    'aliasName'=>'姓名',

                    'isMust'=>true,
                ],
                [
                    'columnName'=>'公司名称',
                    'aliasName'=>'公司名称',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'部门',
                    'aliasName'=>'部门',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'职务',
                    'aliasName'=>'职务',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'手机',
                    'aliasName'=>'手机',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'电话',
                    'aliasName'=>'电话',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'出生年月',
                    'aliasName'=>'出生年月',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'微信号',
                    'aliasName'=>'微信号',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'QQ号',
                    'aliasName'=>'QQ号',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'网址',
                    'aliasName'=>'网址',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'邮箱',
                    'aliasName'=>'邮箱',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'地址',
                    'aliasName'=>'地址',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'线索来源',
                    'aliasName'=>'线索来源',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'跟进状态',
                    'aliasName'=>'跟进状态',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'下次跟进时间',
                    'aliasName'=>'下次跟进时间',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'所属线索池',
                    'aliasName'=>'所属线索池',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'负责人',
                    'aliasName'=>'负责人',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'负责人编号',
                    'aliasName'=>'负责人编号',

                    'isMust'=>true,
                ],
                [
                    'columnName'=>'协作人',
                    'aliasName'=>'协作人',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'协作人编号',
                    'aliasName'=>'协作人编号(多个用英文逗号隔开)',

                    'isMust'=>false,
                ],
                [
                    'columnName'=>'备注',
                    'aliasName'=>'备注',

                    'isMust'=>false,
                ],

            ]
        };
    }

    /**
     * 导出模板字段初始化
     * @return array[]
     */
    public function exportFieldInit($classify=''): array
    {
        return match ($classify) {
            default=>  [
                [
                    'columnName'=>'姓名',
                    'aliasName'=>'姓名',
                ],
                [
                    'columnName'=>'公司名称',
                    'aliasName'=>'公司名称',
                ],
                [
                    'columnName'=>'部门',
                    'aliasName'=>'部门',
                ],
                [
                    'columnName'=>'职务',
                    'aliasName'=>'职务',
                ],
                [
                    'columnName'=>'出生年月',
                    'aliasName'=>'出生年月',
                ],
                [
                    'columnName'=>'手机',
                    'aliasName'=>'手机',
                ],
                [
                    'columnName'=>'电话',
                    'aliasName'=>'电话',
                ],
                [
                    'columnName'=>'微信号',
                    'aliasName'=>'微信号',
                ],
                [
                    'columnName'=>'QQ号',
                    'aliasName'=>'QQ号',
                ],
                [
                    'columnName'=>'网址',
                    'aliasName'=>'网址',
                ],
                [
                    'columnName'=>'邮箱',
                    'aliasName'=>'邮箱',
                ],
                [
                    'columnName'=>'地址',
                    'aliasName'=>'地址',
                ],
                [
                    'columnName'=>'线索来源',
                    'aliasName'=>'线索来源',
                ],
                [
                    'columnName'=>'跟进状态',
                    'aliasName'=>'跟进状态',
                ],
                [
                    'columnName'=>'下次跟进时间',
                    'aliasName'=>'下次跟进时间',
                ],
                [
                    'columnName'=>'所属线索池',
                    'aliasName'=>'所属线索池',
                ],
                [
                    'columnName'=>'标签',
                    'aliasName'=>'标签',
                ],
                [
                    'columnName'=>'负责人',
                    'aliasName'=>'负责人',
                ],
                [
                    'columnName'=>'协作人',
                    'aliasName'=>'协作人',
                ],
                [
                    'columnName'=>'备注',
                    'aliasName'=>'备注',
                ],
                [
                    'columnName'=>'创建人',
                    'aliasName'=>'创建人',
                ],
                [
                    'columnName'=>'更新时间',
                    'aliasName'=>'更新时间',
                ],
                [
                    'columnName'=>'创建时间',
                    'aliasName'=>'创建时间',
                ],
            ]
        };
    }
}
